home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / fastfred.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  8KB  |  282 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. extern unsigned char *galaxian_attributesram;
  14. static const unsigned char *fastfred_color_prom;
  15.  
  16.  
  17. static struct rectangle spritevisiblearea =
  18. {
  19.       2*8, 32*8-1,
  20.       2*8, 30*8-1
  21. };
  22.  
  23. static struct rectangle spritevisibleareaflipx =
  24. {
  25.         0*8, 30*8-1,
  26.         2*8, 30*8-1
  27. };
  28.  
  29. static unsigned char character_bank[2];
  30. static unsigned char color_bank[2];
  31. static int flipscreenx, flipscreeny;
  32. static int canspritesflipx = 0;
  33.  
  34. void jumpcoas_init_machine(void)
  35. {
  36.     canspritesflipx = 1;
  37. }
  38.  
  39. /***************************************************************************
  40.  
  41.   Convert the color PROMs into a more useable format.
  42.  
  43.   bit 0 -- 1  kohm resistor  -- RED/GREEN/BLUE
  44.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  45.         -- 220 ohm resistor  -- RED/GREEN/BLUE
  46.   bit 3 -- 100 ohm resistor  -- RED/GREEN/BLUE
  47.  
  48. ***************************************************************************/
  49.  
  50. static void convert_color(int i, int* r, int* g, int* b)
  51. {
  52.     int bit0, bit1, bit2, bit3;
  53.     const unsigned char *prom = fastfred_color_prom;
  54.     int total = Machine->drv->total_colors;
  55.  
  56.     bit0 = (prom[i + 0*total] >> 0) & 0x01;
  57.     bit1 = (prom[i + 0*total] >> 1) & 0x01;
  58.     bit2 = (prom[i + 0*total] >> 2) & 0x01;
  59.     bit3 = (prom[i + 0*total] >> 3) & 0x01;
  60.     *r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  61.     bit0 = (prom[i + 1*total] >> 0) & 0x01;
  62.     bit1 = (prom[i + 1*total] >> 1) & 0x01;
  63.     bit2 = (prom[i + 1*total] >> 2) & 0x01;
  64.     bit3 = (prom[i + 1*total] >> 3) & 0x01;
  65.     *g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  66.     bit0 = (prom[i + 2*total] >> 0) & 0x01;
  67.     bit1 = (prom[i + 2*total] >> 1) & 0x01;
  68.     bit2 = (prom[i + 2*total] >> 2) & 0x01;
  69.     bit3 = (prom[i + 2*total] >> 3) & 0x01;
  70.     *b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  71. }
  72.  
  73. void fastfred_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  74. {
  75.         int i;
  76.         #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  77.         #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  78.  
  79.  
  80.         fastfred_color_prom = color_prom;    /* we'll need this later */
  81.  
  82.         for (i = 0;i < Machine->drv->total_colors;i++)
  83.         {
  84.                 int r,g,b;
  85.  
  86.                 convert_color(i, &r, &g, &b);
  87.  
  88.                 *(palette++) = r;
  89.                 *(palette++) = g;
  90.                 *(palette++) = b;
  91.         }
  92.  
  93.  
  94.         /* characters and sprites use the same palette */
  95.         for (i = 0;i < TOTAL_COLORS(0);i++)
  96.         {
  97.             int color;
  98.  
  99.             if (!(i & 0x07))
  100.             {
  101.                 color = 0;
  102.             }
  103.             else
  104.             {
  105.                 color = i;
  106.             }
  107.  
  108.             COLOR(0,i) = COLOR(1,i) = color;
  109.         }
  110. }
  111.  
  112.  
  113. WRITE_HANDLER( fastfred_character_bank_select_w )
  114. {
  115.     if (character_bank[offset] != data)
  116.     {
  117.         character_bank[offset] = data & 1;
  118.         memset(dirtybuffer, 1, videoram_size);
  119.  
  120.         //if (offset==1) logerror("CharBank = %02X\n", (character_bank[1] << 1) | character_bank[0]);
  121.     }
  122. }
  123.  
  124.  
  125. WRITE_HANDLER( fastfred_color_bank_select_w )
  126. {
  127.     if (color_bank[offset] != data)
  128.     {
  129.         color_bank[offset] = data & 1;
  130.         memset(dirtybuffer, 1, videoram_size);
  131.  
  132.         //if (offset==1) logerror("ColorBank = %02X\n", (color_bank[1] << 1) | color_bank[0]);
  133.     }
  134. }
  135.  
  136.  
  137. WRITE_HANDLER( fastfred_background_color_w )
  138. {
  139.     int r,g,b;
  140.  
  141.     //logerror("Background color = %02X\n", data);
  142.  
  143.     convert_color(data, &r, &g, &b);
  144.  
  145.     palette_change_color(0,r,g,b);
  146. }
  147.  
  148.  
  149. WRITE_HANDLER( fastfred_flipx_w )
  150. {
  151.     if (flipscreenx != (data & 1))
  152.     {
  153.         flipscreenx = data & 1;
  154.         memset(dirtybuffer,1,videoram_size);
  155.     }
  156. }
  157.  
  158. WRITE_HANDLER( fastfred_flipy_w )
  159. {
  160.     if (flipscreeny != (data & 1))
  161.     {
  162.         flipscreeny = data & 1;
  163.         memset(dirtybuffer,1,videoram_size);
  164.     }
  165. }
  166.  
  167.  
  168. /***************************************************************************
  169.  
  170.   Draw the game screen in the given osd_bitmap.
  171.   Do NOT call osd_update_display() from this function, it will be called by
  172.   the main emulation engine.
  173.  
  174. ***************************************************************************/
  175. void fastfred_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  176. {
  177.         int offs, charbank, colorbank;
  178.  
  179.  
  180.     if (palette_recalc())
  181.         memset(dirtybuffer,1,videoram_size);
  182.  
  183.         charbank   = ((character_bank[1] << 9) | (character_bank[0] << 8));
  184.         colorbank  = ((color_bank[1]     << 4) | (color_bank[0]     << 3));
  185.  
  186.         for (offs = videoram_size - 1;offs >= 0;offs--)
  187.         {
  188.                 int color;
  189.  
  190.                 if (dirtybuffer[offs])
  191.                 {
  192.                         int sx,sy;
  193.  
  194.                         dirtybuffer[offs] = 0;
  195.  
  196.                         sx = offs % 32;
  197.                         sy = offs / 32;
  198.  
  199.                         color = colorbank | (galaxian_attributesram[2 * sx + 1] & 0x07);
  200.  
  201.                         if (flipscreenx) sx = 31 - sx;
  202.                         if (flipscreeny) sy = 31 - sy;
  203.  
  204.                         drawgfx(tmpbitmap,Machine->gfx[0],
  205.                                 charbank | videoram[offs],
  206.                                 color,
  207.                                 flipscreenx,flipscreeny,
  208.                                 8*sx,8*sy,
  209.                                 0,TRANSPARENCY_NONE,0);
  210.                 }
  211.         }
  212.  
  213.         /* copy the temporary bitmap to the screen */
  214.         {
  215.                 int i, scroll[32];
  216.  
  217.  
  218.                 if (flipscreenx)
  219.                 {
  220.                         for (i = 0;i < 32;i++)
  221.                         {
  222.                                 scroll[31-i] = -galaxian_attributesram[2 * i];
  223.                                 if (flipscreeny) scroll[31-i] = -scroll[31-i];
  224.                         }
  225.                 }
  226.                 else
  227.                 {
  228.                         for (i = 0;i < 32;i++)
  229.                         {
  230.                                 scroll[i] = -galaxian_attributesram[2 * i];
  231.                                 if (flipscreeny) scroll[i] = -scroll[i];
  232.                         }
  233.                 }
  234.  
  235.                 copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  236.         }
  237.  
  238.  
  239.         /* Draw the sprites */
  240.         for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  241.         {
  242.                 int code,sx,sy,flipx,flipy;
  243.  
  244.                 sx = (spriteram[offs + 3] + 1) & 0xff;  /* ??? */
  245.                 sy = 240 - spriteram[offs];
  246.  
  247.                 if (canspritesflipx)
  248.                 {
  249.                     // Jump Coaster
  250.                     code  =  spriteram[offs + 1] & 0x3f;
  251.                     flipx = ~spriteram[offs + 1] & 0x40;
  252.                     flipy =  spriteram[offs + 1] & 0x80;
  253.                 }
  254.                 else
  255.                 {
  256.                     // Fast Freddie
  257.                     code  =  spriteram[offs + 1] & 0x7f;
  258.                     flipx =  0;
  259.                     flipy = ~spriteram[offs + 1] & 0x80;
  260.                 }
  261.  
  262.  
  263.                 if (flipscreenx)
  264.                 {
  265.                     sx = 241 - sx;  /* note: 241, not 240 */
  266.                     flipx = !flipx;
  267.                 }
  268.                 if (flipscreeny)
  269.                 {
  270.                     sy = 240 - sy;
  271.                     flipy = !flipy;
  272.                 }
  273.  
  274.                 drawgfx(bitmap,Machine->gfx[1],
  275.                                 code,
  276.                                 colorbank | (spriteram[offs + 2] & 0x07),
  277.                                 flipx,flipy,
  278.                                 sx,sy,
  279.                                 flipscreenx ? &spritevisibleareaflipx : &spritevisiblearea,TRANSPARENCY_PEN,0);
  280.         }
  281. }
  282.